package Servlets.yz;

import Util.GokJDBCUtil2;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
/*
* 用于实现用户封禁和解封功能
* */
@WebServlet(name=("BanUserServlet"),urlPatterns = ("/BanUserServlet"))
public class BanUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        String id = req.getParameter("id");
        String method = req.getParameter("method");
        if("ban".equals(method)){
            String sql = "update user set userstatus=1 where id=?";
            GokJDBCUtil2.update(sql,id);
        }
        else {
            String sql = "update user set userstatus=0 where id=?";
            GokJDBCUtil2.update(sql,id);
        }

        resp.sendRedirect(req.getContextPath()+"/UserShowServlet");
        writer.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
